﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Security;

public partial class Info : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
      
        if (!IsPostBack)
        {
           
            SqlConnection konekcija = new SqlConnection();
            konekcija.ConnectionString = ConfigurationManager.ConnectionStrings["mojaKonekcija"].ConnectionString;
            string sqlString = "SELECT ime FROM Info";
            SqlCommand komanda = new SqlCommand(sqlString, konekcija);
            try
            {
                konekcija.Open();
                SqlDataReader citac = komanda.ExecuteReader();
                while (citac.Read())
                {
                    lblNaslov.Text = citac["ime"].ToString();
                }
                citac.Close();
            }
            catch (Exception err)
            {
                lblNaslov.Text = err.Message;
            }
            finally
            {
                konekcija.Close();
            }
            Info_popolni();
        }
        if (isUserLoggedIn())
        {
            btnOdlogiranje.Visible = true;
            lblKorisnik.Text = "Најавен корисник: "+(string)Session["korisnik"];
            return;

        }
        else
        {
            btnLogiranje.Visible = true;
        }
    }
    private bool isUserLoggedIn()
    {
        if (HttpContext.Current.User != null)
        {
            if (HttpContext.Current.User.Identity.IsAuthenticated)
            {
                return true;
            }
        }
        return false;
    }
    protected void Info_popolni()
    {
        SqlConnection konekcija = new SqlConnection();
        konekcija.ConnectionString = ConfigurationManager.ConnectionStrings["mojaKonekcija"].ConnectionString;
        string sqlString = "SELECT * FROM Info";
        SqlCommand komanda = new SqlCommand(sqlString, konekcija);
        try
        {
            konekcija.Open();
            SqlDataReader citac = komanda.ExecuteReader();
            if (citac.Read())
            {
                lblAdresa.Text = citac["adresa"].ToString();
                lblimeKompanija.Text = citac["ime"].ToString();
                lblMail.Text = citac["mail"].ToString();
                lblTelefon.Text = citac["telefon"].ToString();
                citac.Close();
            }

        }
        catch (Exception err)
        {
        }
        finally
        {
            konekcija.Close();
        }
    }
    protected void Menu2_MenuItemClick(object sender, MenuEventArgs e)
    {
        if (Menu2.SelectedValue == "Маици")
            Response.Redirect("za_mazi.aspx?tip=maici");
        if (Menu2.SelectedValue == "Патики")
            Response.Redirect("za_mazi.aspx?tip=patiki");
        if (Menu2.SelectedValue == "Панталони")
            Response.Redirect("za_mazi.aspx?tip=pantaloni");
        if (Menu2.SelectedValue == "Фустани")
            Response.Redirect("za_zeni.aspx?tip=fustani");
        if (Menu2.SelectedValue == "Штикли")
            Response.Redirect("za_zeni.aspx?tip=stikli");
        if (Menu2.SelectedValue == "Капи")
            Response.Redirect("za_zeni.aspx?tip=kapi");
        if (Menu2.SelectedValue == "Облека за мажи")
            Response.Redirect("za_mazi.aspx?tip=mazi");
        if (Menu2.SelectedValue == "Облека за жени")
            Response.Redirect("za_zeni.aspx?tip=zeni");
    }
    protected void btnLogiranje_Click(object sender, EventArgs e)
    {
        Response.Redirect("Login.aspx");
    }
    protected void btnOdlogiranje_Click(object sender, EventArgs e)
    {
        FormsAuthentication.SignOut();

        // kolaceto istekuva vcera, t.e. ne e validno
        if (FormsAuthentication.FormsCookieName != null)
        {
            Context.Response.Cookies[FormsAuthentication.FormsCookieName].Expires = DateTime.Now.AddDays(-1);
        }

        // prefrli na default stranata
        Response.Redirect("Doma.aspx");
    }
}